#include "led.h"

void timerLedOut(void * parameter)
{
    LIGHT_RUN_TOGGLE;
    //收到消息队列消息
}
static void TimerLed_init()
{
    rt_timer_t timerLed;
    timerLed = rt_timer_create("timerLed", timerLedOut, RT_NULL, 500, RT_TIMER_FLAG_PERIODIC);
    rt_timer_start(timerLed);
}

static void Device_init()
{
    rt_device_t dev = rt_device_find("led_gpio");
    if (dev)
    {
        rt_device_open(dev, RT_DEVICE_OFLAG_RDWR);
    }  
}
void led_thread_entry(void *parameter)
{
    int i=0;
    rt_err_t result;
    
    TimerLed_init();
    Device_init();

    while(1)
    {
        result = rt_mq_recv(mqLed_handle, &Queuemsg, sizeof(Queuemsg), RT_WAITING_NO);
        if (result != RT_ERROR) 
        {
//            rt_kprintf("Received: id=%d, data=%d\n", Queuemsg.id, Queuemsg.data);
            (Queuemsg.data == 1)?LIGHT_PWR_OPEN:LIGHT_PWR_STOP;
        } 
        else 
        {
            rt_kprintf("Receive message failed.\n");
        }
        rt_thread_delay(100);
    }
}

